# -*- coding: utf-8 -*-

"""
=============================
this is a feibot product,
all rights reserved.
www.feibot.com
@author: Gu Tianyuan
@email: g@feibot.com
@time: ${DATE}:${TIME}
@product: ${PRODUCT_NAME}
=============================
"""
import os


# 返回文档的git信息
def getGitHeadInfo():
    commitId = ''
    branchName = ''
    try:
        commitId = os.popen('git --git-dir ~/platform/.git rev-parse --short HEAD').read()
        lines = os.popen('git --git-dir ~/platform/.git branch').readlines()
        for line in lines:
            if '*' in line:
                if 'dev' in line:
                    branchName = 'dev'
                if 'master' in line:
                    branchName = 'master'
                if 'zzz' in line:
                    branchName = 'zzz'
    except Exception as e:
        print(e)
        pass
    return commitId.strip()[0:4], branchName.strip()


# 列出远程版本的信息
def gitListRemoteVersion():
    devNew = ''
    masterNew = ''
    print('=======获取远程版本信息=====...')
    lines = os.popen('git --git-dir ~/platform/.git ls-remote').readlines()
    for line in lines:
        if 'refs/heads/dev' in line:
            devNew = line[0:4]
            print('dev', devNew)
        if 'refs/heads/master' in line:
            masterNew = line[0:4]
            print('master', masterNew)
    if devNew == '' or masterNew == '':
        return['error','error']
    return [devNew,masterNew]


if __name__ == '__main__':
    gitListRemoteVersion()
